﻿using DncLite.Application.Interfaces;
using DncLite.Application.Services;
using DncLite.Domain.CommandHandlers;
using DncLite.Domain.Commands.Student;
using DncLite.Domain.Core.Bus;
using DncLite.Domain.Interfaces;
using DncLite.Infra.Bus;
using DncLite.Infrastruct.Data.Context;
using DncLite.Infrastruct.Data.Repository;
using DncLite.Infrastruct.Data.UoW;
using MediatR;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace DncLite.Infra.IoC
{
    public class NativeInjectorBootStrapper
    {
        public static void RegisterServices(IServiceCollection services)
        {
            // 注入 Application
            services.AddScoped<IStudentAppService, StudentAppService>();

            // Domain Bus (Mediator)
            services.AddScoped<IMediatorHandler, InMemoryBus>();


            // Domain - Commands
            services.AddScoped<IRequestHandler<RegisterStudentCommand, Unit>, StudentCommandHandler>();
            //services.AddScoped<IRequestHandler<UpdateStudentCommand, Unit>, StudentCommandHandler>();
            //services.AddScoped<IRequestHandler<RemoveStudentCommand, Unit>, StudentCommandHandler>();

            // Domain - Memory
            services.AddSingleton<IMemoryCache>(factory =>
            {
                var cache = new MemoryCache(new MemoryCacheOptions());
                return cache;
            });



            // 注入 Infra - Data
            services.AddScoped<IStudentRepository, StudentRepository>();
            services.AddScoped<StudyContext>();
            services.AddScoped<IUnitOfWork, UnitOfWork>();
        }
    }
}
